﻿ 
using SHKF.B2C.Model.Entity.Center;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Text; 

namespace SHKF.B2C.BLL.Center
{
    public class CompanyBLL : CenterBLL
    {
   
        public CompanyBLL(SqlSugarClient db) : base(db)
        {
             
        }

        public List<CompanyEntity> Query(string companyName)
        {
            var list = this.db
                .Queryable<CompanyEntity>()
                .Where(oo => oo.CompanyName.Contains(companyName))
                .ToList();

            return list;
        }

        public CompanyEntity Get(long companySN)
        {
            CompanyEntity company = this.db
                .Queryable<CompanyEntity>()
                .Where(ww => ww.SN == companySN)
                .First(); 
            return company;
        }

        public CompanyEntity Save(CompanyEntity company)
        {
            int iResult = 0;
            if (company.SN == 0)
            {
                company.CreateDate = DateTime.Now;
                company.SN = this.db.Insertable<CompanyEntity>(company).ExecuteReturnBigIdentity(); 
            }
            else
            {
                iResult = this.db.Updateable<CompanyEntity>(company).ExecuteCommand(); 
            } 
            return company;
        }

        public int Delete(int SN)
        { 
            int result = this.db.Deleteable<CompanyEntity>().In(SN).ExecuteCommand(); 
            return result;
        }

        public int UpdateStop(CompanyEntity company)
        {
            int iResult = this.db.Updateable<CompanyEntity>(company).ExecuteCommand(); 
            return iResult;
        }
    }
}
